<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h:form id="registrationForm" enctype="multipart/form-data">
                <br/>
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <div class="row">
                    <div class="twelve columns"> 
                        <fieldset>
                            <br/>
                            <div style="float: left;width: 100%">
                                <h3 class="title" style="float: left">Averbação de mudança de nome</h3>
                            </div>

                            <ui:include src="averbacao_header.xhtml"/>  
                            <ui:include src="averbacao_footer.xhtml"/>  

                            <p:panel id="panel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">

                                <p:dataTable id="tableProprietario" var="item" value="#{managerRegistration.imovel.proprietarios}" 
                                             styleClass="grid_24" emptyMessage="Nenhum registro">  
                                    <f:facet name="header">
                                        Nome do Proprietário ou Detentor
                                    </f:facet>

                                    <p:column headerText="Ação" style="text-align: center">
                                        <p:commandButton  styleClass="optionButton" alt="Mudar Nome"
                                                          process="@this" icon="ui-icon-pencil"
                                                          actionListener="#{managerRegistration.mudaProprietario(item)}"
                                                          update=":registrationForm:dlgNewName"
                                                          oncomplete="dlgNewName.show()" />
                                    </p:column>

                                    <p:column headerText="Nome">  
                                        #{item.tipoDocumento ne null ? 
                                          (item.tipoDocumento eq 'CPF' ? item.nome : item.nomeFantasia) : 
                                          (item.nome ne null and item.nome ne '' ? item.nome : item.nomeFantasia)}
                                    </p:column>

                                    <p:column headerText="Documento" >  
                                        #{item.formatedDocument()}
                                    </p:column> 

                                </p:dataTable>   
                            </p:panel>

                        </fieldset>
                        <div class="buttonAction">
                            <p:button href="pesquisarimovel.xhtml" process="@this" value="Cancelar"  icon="ui-icon-trash" />
                        </div >

                        <p:dialog header="Mudança de nome" id="dlgNewName" widgetVar="dlgNewName" width="325" modal="true">
                            <p:outputLabel value="Novo nome" styleClass="grid_24"  />
                            <p:inputText value="#{managerRegistration.newName}" styleClass="grid_24" />
                            <div class="buttonAction grid_24" >
                                <p:commandButton value="Salvar" icon="ui-icon-disk"
                                                 id="saveButton"
                                                 actionListener="#{managerRegistration.saveAverbacaoPorNome()}"
                                                 styleClass="ui-priority-primary"   />
                                <p:button href="#" onclick="dlgNewName.hide()" value="Cancelar"  icon="ui-icon-trash" />
                            </div >

                        </p:dialog>
                        <br/>
                        <ui:include src="averbacao_dialog.xhtml"/>  

                    </div>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
